<?php
/*
 * Created on Oct 27, 2011
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

require_once('custom/modules/Tasks/TaskUtils.php');
 class TaskHooks
{
	
	function taskhooks(&$bean, $event, $arguments)
	{
		$this->task_assigned($bean);
		if($bean->type == 'FastFail')
		{
		$this->deliverable_fast_fail($bean->deliverable_id);
		}
	}
	
	function deliverable_fast_fail($deliverable_id)
	{
		$deliverable = new edanz_Deliverables();
		$deliverable->retrieve($deliverable_id);
		$deliverable->fast_fail = 1;
		$deliverable->save();				
	}
	
	function task_assigned(&$bean, $event, $arguments) {
		global $db;
		require_once('modules/edanz_Editor/edanz_Editor.php');
		$editor = new edanz_Editor();
		$editor->retrieve($bean->related_editor_id);
		if($editor->isNewEditor() and $bean->status == "Deferred")
		{
			$flag = new edanz_Flags();
			$flag_list = $flag->get_full_list();
			$flags_id =array();
			foreach($flag_list as $list)
			{
				if($list->name == "New Editor")	
				{
						$flags_id[]= $list->id;
				}				
			}
			if(!empty($flags_id))
			{
				foreach($flags_id as $flag_id)
				{
					$deliverable_id= $bean->deliverable_id;
					$query_delet = "DELETE FROM edanz_deliverables_flags WHERE edanz_deliverables_flags.deliverables_id ='$deliverable_id' and edanz_deliverables_flags.flags_id in ('$flag_id')";
			        $db->query($query_delet);
				}
			}
		}	
		if($editor->isOnProbation()and $bean->status == "Deferred")
		{
			$flag = new edanz_Flags();
			$flag_list = $flag->get_full_list();
			$flags_id =array();
			foreach($flag_list as $list)
			{
				if($list->name == "ProbationEditor")	
				{
						$flags_id[]= $list->id;
				}				
			}
			if(!empty($flags_id))
			{
				foreach($flags_id as $flag_id)
				{
					$deliverable_id= $bean->deliverable_id;
					$query_delet = "DELETE FROM edanz_deliverables_flags WHERE edanz_deliverables_flags.deliverables_id ='$deliverable_id' and edanz_deliverables_flags.flags_id in ('$flag_id')";
			        $db->query($query_delet);
				}
			}
		}
	}
	 
} 
?>
